package MyApp;
use Mojo::Base 'Mojolicious';
use Mojo::mysql;
use Workflow::Factory qw( FACTORY );
use Log::Log4perl qw( get_logger );

#use MyApp::Model::Users;


sub startup {
	my $self = shift;

	$self->secrets(['Lovol IT']);

	#$self->helper(users=>sub{ state $users = MyApp::Model::Users->new });
	$self->helper(mysql=>sub{ state $mysql = Mojo::mysql->strict_mode('mysql://dahama:XXXXxxxxx@localhost/vpninfo') });

	#工作流程初始化
	Log::Log4perl::init('log4perl.conf');

	FACTORY->add_config_from_file(
		workflow => "Configure/workflow.xml",
		action   => "Configure/action.xml",
		condition => "Configure/condition.xml",
		persister => "Configure/persister.xml"
	);
	FACTORY->add_config_from_file(
		workflow => "Configure/account_workflow.xml",
		action   => "Configure/action.xml",
		condition => "Configure/condition.xml",
		persister => "Configure/persister.xml"
	);
	FACTORY->add_config_from_file(
		workflow => "Configure/mac_workflow.xml",
		action   => "Configure/action.xml",
		condition => "Configure/condition.xml",
		persister => "Configure/persister.xml"
	);


	# Load configuration from hash returned by "my_app.conf"
	my $config = $self->plugin('Config');

	# Documentation browser under "/perldoc"
	#$self->plugin('PODRenderer') if $config->{perldoc}; #新版本mojolicious已经取消了该插件

	# Router
	my $r = $self->routes;

	# Normal route to controller
	$r->any('/')->to('login#login')->name('index'); #登录页
	$r->any('/loginquest')->to('login#loginquest'); #登录页的认证查询请求


	my $l = $r->under('/')->to('login#logged_in');
	$l->get('/protected')->to('login#protected')->name('home'); #应用页
	$l->any('/getrole')->to('login#getrole'); #查询用户权限信息，前段Vue-Router根据此信息自动加载相应页面路由
	$l->get('/getloggedpermition')->to('login#getloggedpermition');

	#以下业务数据交互接口：
	$l->get('/show_admin_account')->to('registadmin#show_admin_account'); #获取管理员账户列表
	$l->any('/add_admin_account')->to('registadmin#add_admin_account');
	$l->any('/edit_admin_account')->to('registadmin#edit_admin_account');
	$l->get('/get_id_values')->to('registadmin#get_id_values');
	$l->get('/get_adminlist')->to('registadmin#get_adminlist');
	$l->get('/searchcompany')->to('workflow#searchcompany');
	$l->get('/getpassinfo')->to('registadmin#get_pass_info');
	$l->post('/updateadmininfo')->to('registadmin#update_admin_info');

	#获取台账信息：
	$l->get('/get_taizhanginfos')->to('taizhang#get_information');
	$l->get('/get_dealing')->to('taizhang#get_dealing');

	#下为workflow工作流程相关业务交互接口：
	$l->get('/get_my_workflow')->to('workflow#get_my_workflow');
	$l->get('/get_daiban')->to('workflow#get_daiban');
	$l->get('/get_companyapplication_info')->to('workflow#get_companyapplication_info');
	$l->any('/input_company_info')->to('workflow#input_company_info');
	$l->get('/agree_companyinfo')->to('workflow#agree_companyinfo');
	$l->get('/disagree_companyinfo')->to('workflow#disagree_companyinfo');
	$l->get('/flowmanage')->to('workflow#get_flowmanage');
	$l->get('/getappinfos')->to('workflow#get_application_info');
	$l->get('/get_accountapplication_info')->to('workflow#get_accountapplication_info');
	$l->any('/input_account_info')->to('workflow#input_account_info');
	$l->get('/agree_accountinfo')->to('workflow#agree_accountinfo');
	$l->get('/disagree_accountinfo')->to('workflow#disagree_accountinfo');
	$l->get('/get_macapplication_info')->to('workflow#get_macapplication_info');
	$l->any('/input_mac_info')->to('workflow#input_mac_info');
	$l->get('/agree_macinfo')->to('workflow#agree_macinfo');
	$l->get('/disagree_macinfo')->to('workflow#disagree_macinfo');
	$l->get('/get_my_last_finish_flow')->to('workflow#get_lastfinish');

	#管理员处理部分：
	#下载文件
	my $a = $l->under('/')->to('login#is_admin');
	$a->get('/get_dealedxml')->to('taizhang#get_dealedxml');
	$a->post('/uploadxml')->to('taizhang#uploadxml');
	$a->get('/deallist')->to('taizhang#deallist');

	#系统利用selenium自动处理VPN系统配置文件：
	$a->get('/autodealing')->to('selenium#auto_operation');

	#下行为测试连接:


	#退出页
	$l->get('/logout')->to('login#logout');

	$r->get('/welcome')->to('example#welcome');#就测试模板，没有用了
	$r->any('/login')->to('login#index'); #旧登录页，已经无用。
}

1;
